﻿using System;
using System.Linq;
using AidBrella.BLL;
using System.Web.Mvc;

namespace AidBrella.UIHelpers
{
    public static class HtmlHelpers
    {
        /// <summary>
        /// Returns a welcome title for a logged in user in UserFrontPage
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static string GetLoginUserName(this HtmlHelper helper, string userName)
        {
            var model = new UserModel();
            var id = model.GetUserId(userName);
            var user =  model.GetEntities().UserSet.Where(u => u.Id == id);
            return user.Count() == 1 ? String.Format("Welcome {0} {1}", user.First().FirstName.ToUpper(), user.First().LastName.ToUpper()) : string.Empty;
        }

        /// <summary>
        /// Returns a feed div element with click events hooked
        /// </summary>
        /// <param name="status"></param>
        /// <param name="submitedBy"></param>
        /// <param name="logoUrl"></param>
        /// <param name="projectId"></param>
        /// <param name="feedId"></param>
        ///  /// <param name="cmtId"></param>
        ///  /// <param name="cmt"></param>
        ///  /// <param name="cmtBy"></param>
        /// <returns></returns>
        public static string GetFeedHtml(string status, string submitedBy, string logoUrl, int projectId, int feedId, int cmtId, string cmt, string cmtBy)
        {
           var html = string.Empty;
            html += "<div class=" + "row" + "><div class=" + "cols2>" + "<a href=" + "/" + "Project/View/" + projectId + "><img src=" + logoUrl + "/></a></div>";
            html += "<div  id=" + "feed-" + feedId + " " + " class=" + "cols2>" + "<p class=" + "p-status" + ">" + status + "</p> <p class=" + "p-updateinfo>" + "status by <b>" + submitedBy + "</b><a id=" + feedId + " onclick=" + "comment(" + feedId + ");" + " href= " + "#>" + "<b  class=" + "b-comment>" + " comment </b></a> </p>";
            html += "<div id=" + "comment-id" + cmtId + " " +" class=" + "feed-comment><p class=" +"p-updateinfo> comment by "+ cmtBy +"</p>" +cmt +" </div></div></div>"; 
            return html;
        }
    }
}